<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class JxsyglController extends AdminController{
   
   //教学实验计划概要表
	public function jxsyjhgy(){
		$where = '1=1';
		$where .= I('get.course_id', -1) > -1 ? ' and course_id =' . I('get.course_id') : '';
		$list = $this->getList('*', 'jhgy', $where, 'id desc', flase,null);
		$this->assign('list', $list);
		$list_course = $this->getList('id,name', 'course',null,'id desc',flase,null);
		$this->assign('list_course', $list_course);
		$list_sxxm = $this->getList('id,name', 'syxm',null,'id desc',flase,null);
		$this->assign('list_sxxm', $list_sxxm);
		$list_ssxx = $this->getList('id,name', 'js_base','pid=42');
		$this->assign('list_ssxx', $list_ssxx);
		$this->display();
	}
	//添加概要表
	public function jxsyjhgyadd(){
		if(IS_POST){
			$info = $this->getInfo('*', 'js_base', array('id' => $_POST['sys_id']));
            $_POST['sys']=$info['name'];
            $info_course = $this->getInfo('*', 'course', array('id' => $_POST['course_id']));
            $_POST['course']=$info_course['name'];
            $info_syxm = $this->getInfo('*', 'syxm', array('id' => $_POST['syxm_id']));
            $_POST['syxm']=$info_syxm['name'];
			$_POST['time']=strtotime($_POST['time']);
			$result = $this->updateData($_POST, 'jhgy');
			$this->returnResult($result,null,U('Jxsygl/jxsyjhgy'));
		}
	}
	//修改概要表
	public function jxsyjhgyedit(){
		if(IS_POST){
			$info = $this->getInfo('*', 'js_base', array('id' => $_POST['sys_id']));
            $_POST['sys']=$info['name'];
            $info_course = $this->getInfo('*', 'course', array('id' => $_POST['course_id']));
            $_POST['course']=$info_course['name'];
            $info_syxm = $this->getInfo('*', 'syxm', array('id' => $_POST['syxm_id']));
            $_POST['syxm']=$info_syxm['name'];
			$_POST['time']=strtotime($_POST['time']);
			$result = $this->updateData($_POST, 'jhgy',2);
			$this->returnResult($result,null,U('Jxsygl/jxsyjhgy'));
		}else{
			$info = $this->getInfo('*', 'jhgy', array('id' => I('get.id', 0, 'intval')));
			if($info){
				$data['info'] = $info;
				$data['status'] = 1;
			}else{
				$data['info'] = '数据不存在';
				$data['status'] = 0;
			}
			$this->ajaxReturn($data);
		}
	}
	//删除概要表
	public function jxsyjhgydel(){
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'jhgy');
		$this->returnResult($result);
	}

	//教学实验课程计划制定
	public function jxsykcjh(){
        $select_info = array('nf'=>date('Y'),'yf'=>date('n'),'bm' => '');
		$_now_m = date("Y-m-");
		if(I('nf') && I('yf')){
			$select_info = array('nf'=>I('nf','','intval'),'yf'=>I('yf','','intval'),'bm' => '');
			$_now_m = $select_info['nf']."-".$select_info['yf']."-";
		}
/*		if(session('adminInfo.gid') > 2){
			//普通用户自动带入部门信息
			$select_info['bm'] = session('adminInfo.dep_id');
			$dep_id = session('adminInfo.dep_id');
			//部门特殊控制
			$ts = require CONF_PATH . 'yjpb.php';
			if(in_array($dep_id,$ts['dep_ids'])){
				//派出所特殊排班
				$depList = $ts['dep_list'][$dep_id];
			}else{
				$depList = $this->getList("id,name", "dep","id = '{$dep_id}'","sort desc,id desc");
			}
		}else{
			//管理员用户
			$depList = $this->getList('*', 'dep', "length(name) > 0", 'sort desc');
		}
		$this->assign('select_bm', $depList);
		
		if(I('bm')){
			$select_info['bm'] = I('bm','','intval');
		}
		if(strlen($select_info['bm']) == 0){
			$select_info['bm'] = $depList[0]['id'];
		}

		$where = " and bm_id = {$select_info['bm']}";
		$this->assign('select_info', $select_info);*/

		$_time_stamp_start = strtotime($_now_m."01");
		$_time_stamp_end = strtotime($_now_m.date("t"));
		//月初判断是否为周的第一天0：周日；并算出整周显示的第一天
		$_nowM_first_info = getdate($_time_stamp_start);
		if($_nowM_first_info['wday'] > 0){
			$_d = bcsub(0,$_nowM_first_info['wday']);
			$_time_stamp_start = strtotime($_now_m."01"." ".$_d." day");
		}

		//月末判断，周的最后一天6：周六；并算出整周显示的最后一天
		$_nowM_end_info = getdate($_time_stamp_end);
		if($_nowM_end_info['wday'] < 6){
			$e = bcsub(6,$_nowM_end_info['wday']);
			$_time_stamp_end = strtotime($_now_m.date("t")." +".$e." day");
		}
		//重置当前月份值；
		$_reinfo = array();
		$i = $_time_stamp_start;
		while( $i <=$_time_stamp_end){
			$_day_show = date("Y-m-d",$i);
			$_re = array(
				"time_stamp" 	=> $i,
				"dateformat"	=> $_day_show,
				"dateInfo"		=> getdate($i),
				"is_day_info"		=> 'by_'	//本月
			);

			if(date("m") == $_re['dateInfo']['mon'] && $_day_show == date("Y-m-d")){
				$_re['is_day_info'] = 'dt_';		//当天
			}elseif(date("m") != $_re['dateInfo']['mon']){
				//判断非本月
				$_re['is_day_info'] = 'nby_';	//非本月
			}

			$_re['dateInfo']['dayInfo'] = strtotime($_re['dateInfo']['year']."-".$_re['dateInfo']['mon']."-".$_re['dateInfo']['mday']);
			$_now_e = bcadd($i,(60*60*24));
			$_pv = array();
			/*
			$_re_duty = $this->getInfo('id,bmmc,zbr,bm_id,zbr_nameshow', 'duty', "isdel = 0 and zbrq >= {$i} and zbrq < {$_now_e}".$where);
		   if($_re_duty){
				$_pv = $_re_duty;
				$zbr_show_all = "&#10";$zbr_show = "";
				if(strlen($_pv['zbr_nameshow']) > 0){
					$_pv['bmmc'] = str_replace("镜湖分局","",$_pv['bmmc']);
				}

				if(strlen($_pv['zbr_nameshow']) > 0){
					$zbr_show		=	explode(",",$_pv['zbr_nameshow']);
					$zbr_show		=	array_slice($zbr_show,0,8);
					$zbr_show		=	implode(",",$zbr_show);

					$zbr_show_all 	.=	str_replace(",","&#10",$_pv['zbr_nameshow']);
				}
				$_pv['zbr_show'] = $zbr_show;
				$_pv['title_show'] = $zbr_show_all."&#10";
			}*/

			//$_re['project_duty'] = $_pv;
			$_reinfo[] = $_re;
			$i = bcadd($i,(60*60*24));
		}
		$this->assign('dateList', $_reinfo);		
	  /*  $sql = "select nf from app_duty group by nf";
		$Model = new \Think\Model();
		$select_nf = $Model->query($sql);*/
		$nf="2019,2020";
		$select_nf=explode(',',$nf);
		$this->assign('select_nf', $select_nf);
		$this->display();
	}
	//教学实验课程计划制定(申请)
	public function jxsykcjhsq(){
		if(IS_POST){
            $_POST['ctime']=time();
            $info = $this->getInfo('*', 'js_base', array('id' => $_POST['sys_id']));
            $_POST['sys']=$info['name'];
            $info_course = $this->getInfo('*', 'course', array('id' => $_POST['syc_id']));
            $_POST['sy_course']=$info_course['name'];
            $_POST['tea_id']=session('adminInfo.id');
            $_POST['date_y']=date('Y');
            $_POST['date_m']=I('get.m_id', 0, 'intval');
            $_POST['date_d']=I('get.d_id', 0, 'intval');
            $_POST['syrq']=strtotime($_POST['date_y']-$_POST['date_m']-$_POST['date_d']);
            $_show =  include(CONF_PATH . 'kcjd.php');
		    $_POST['syrq_q']=$_show['jd'.$a.'_s'];
            $_POST['syrq_z']=$_show['jd'.$a.'_e'];
			$result = $this->updateData($_POST, 'jxsy');
			$this->returnResult($result,null,U('Jxsygl/jxsykcjh'));
		}else{
			$list_ssxx = $this->getList('id,name', 'js_base','pid=42');
		    $this->assign('list_ssxx', $list_ssxx);
		    $list_course = $this->getList('id,name', 'course',null,'id desc');
		    $this->assign('list_course', $list_course);
			$this->display();
		}
	}

    //课程实验计划审核调整
	public function kcsyjh(){
		$where = '1=1';
		$where .= I('get.teacher') ? ' and teacher like "%' . I('get.teacher') . '%"' : '';
		$list = $this->getList('*', 'jxsy', $where, 'id desc', flase,null);
		$this->assign('list', $list);
		$this->display();
	}
	//审核
	public function kcsyjhsh(){
		 if(IS_POST){
			$result = $this->updateData($_POST, 'jxsy',2);
			$this->returnResult($result);
		}else{
			$info = $this->getInfo('*', 'jxsy', array('id' => I('get.id', 0, 'intval')));
			if($info){
				$data['info'] = $info;
				$data['status'] = 1;
			}else{
				$data['info'] = '数据不存在';
				$data['status'] = 0;
			}
			$this->ajaxReturn($data);
		}
	}
		//审核
	public function kcsyjhselect(){
		$info = $this->getInfo('*', 'jxsy', array('id' => I('get.id', 0, 'intval')));
		$this->assign('info',$info);
		$this->display();
	}
    //实验项目分配
	public function syxmfp(){
		       $select_info = array('nf'=>date('Y'),'yf'=>date('n'),'bm' => '');
		$_now_m = date("Y-m-");
		if(I('nf') && I('yf')){
			$select_info = array('nf'=>I('nf','','intval'),'yf'=>I('yf','','intval'),'bm' => '');
			$_now_m = $select_info['nf']."-".$select_info['yf']."-";
		}
        /*if(session('adminInfo.gid') > 2){
			//普通用户自动带入部门信息
			$select_info['bm'] = session('adminInfo.dep_id');
			$dep_id = session('adminInfo.dep_id');
			//部门特殊控制
			$ts = require CONF_PATH . 'yjpb.php';
			if(in_array($dep_id,$ts['dep_ids'])){
				//派出所特殊排班
				$depList = $ts['dep_list'][$dep_id];
			}else{
				$depList = $this->getList("id,name", "dep","id = '{$dep_id}'","sort desc,id desc");
			}
		}else{
			//管理员用户
			$depList = $this->getList('*', 'dep', "length(name) > 0", 'sort desc');
		}
		$this->assign('select_bm', $depList);
		
		if(I('bm')){
			$select_info['bm'] = I('bm','','intval');
		}
		if(strlen($select_info['bm']) == 0){
			$select_info['bm'] = $depList[0]['id'];
		}

		$where = " and bm_id = {$select_info['bm']}";
		$this->assign('select_info', $select_info);*/

		$_time_stamp_start = strtotime($_now_m."01");
		$_time_stamp_end = strtotime($_now_m.date("t"));
		//月初判断是否为周的第一天0：周日；并算出整周显示的第一天
		$_nowM_first_info = getdate($_time_stamp_start);
		if($_nowM_first_info['wday'] > 0){
			$_d = bcsub(0,$_nowM_first_info['wday']);
			$_time_stamp_start = strtotime($_now_m."01"." ".$_d." day");
		}

		//月末判断，周的最后一天6：周六；并算出整周显示的最后一天
		$_nowM_end_info = getdate($_time_stamp_end);
		if($_nowM_end_info['wday'] < 6){
			$e = bcsub(6,$_nowM_end_info['wday']);
			$_time_stamp_end = strtotime($_now_m.date("t")." +".$e." day");
		}
		//重置当前月份值；
		$_reinfo = array();
		$i = $_time_stamp_start;
		while( $i <=$_time_stamp_end){
			$_day_show = date("Y-m-d",$i);
			$_re = array(
				"time_stamp" 	=> $i,
				"dateformat"	=> $_day_show,
				"dateInfo"		=> getdate($i),
				"is_day_info"		=> 'by_'	//本月
			);

			if(date("m") == $_re['dateInfo']['mon'] && $_day_show == date("Y-m-d")){
				$_re['is_day_info'] = 'dt_';		//当天
			}elseif(date("m") != $_re['dateInfo']['mon']){
				//判断非本月
				$_re['is_day_info'] = 'nby_';	//非本月
			}

			$_re['dateInfo']['dayInfo'] = strtotime($_re['dateInfo']['year']."-".$_re['dateInfo']['mon']."-".$_re['dateInfo']['mday']);
			$_now_e = bcadd($i,(60*60*24));
			$_pv = array();
			/*
			$_re_duty = $this->getInfo('id,bmmc,zbr,bm_id,zbr_nameshow', 'duty', "isdel = 0 and zbrq >= {$i} and zbrq < {$_now_e}".$where);
		   if($_re_duty){
				$_pv = $_re_duty;
				$zbr_show_all = "&#10";$zbr_show = "";
				if(strlen($_pv['zbr_nameshow']) > 0){
					$_pv['bmmc'] = str_replace("镜湖分局","",$_pv['bmmc']);
				}

				if(strlen($_pv['zbr_nameshow']) > 0){
					$zbr_show		=	explode(",",$_pv['zbr_nameshow']);
					$zbr_show		=	array_slice($zbr_show,0,8);
					$zbr_show		=	implode(",",$zbr_show);

					$zbr_show_all 	.=	str_replace(",","&#10",$_pv['zbr_nameshow']);
				}
				$_pv['zbr_show'] = $zbr_show;
				$_pv['title_show'] = $zbr_show_all."&#10";
			}*/

			//$_re['project_duty'] = $_pv;
			$_reinfo[] = $_re;
			$i = bcadd($i,(60*60*24));
		}
		$this->assign('dateList', $_reinfo);		
	  /*  $sql = "select nf from app_duty group by nf";
		$Model = new \Think\Model();
		$select_nf = $Model->query($sql);*/
		$nf="2019,2020";
		$select_nf=explode(',',$nf);
		$this->assign('select_nf', $select_nf);
		$this->display();
	}
	//实验项目分配设置
	public function syxmfpsq(){
		if(IS_POST){
            $_POST['ctime']=time();
            $info = $this->getInfo('*', 'syxm', array('id' => $_POST['syxm_id']));
            $_POST['sy_xm']=$info['name'];
            $_POST['tea_id']=session('adminInfo.id');
            $_POST['date_y']=date('Y');
            $_POST['date_m']=I('get.m_id', 0, 'intval');
            $_POST['date_d']=I('get.d_id', 0, 'intval');
            $_POST['syrq']=strtotime($_POST['date_y']-$_POST['date_m']-$_POST['date_d']);
            $_show =  include(CONF_PATH . 'kcjd.php');
		    $_POST['syrq_q']=$_show['jd'.$a.'_s'];
            $_POST['syrq_z']=$_show['jd'.$a.'_e'];
			$result = $this->updateData($_POST, 'syxm_fp');
			$this->returnResult($result,null,U('Jxsygl/syxmfp'));
		}else{
			$list_xm = $this->getList('id,name', 'syxm',null,'id desc');
		    $this->assign('list_xm', $list_xm);
			$this->display();
		}
	}
    //教学计划统计
	public function jxjhtj(){
		$this->display();
	}
	//教学实验统计
	public function jxsytj(){
		if(I('get.select')=='sy_xm'){
			$list_xm = $this->getList('*', 'syxm_fp',null,'id desc');
		    $this->assign('list_xm', $list_xm);
		}else{
		    $list = $this->getList('*', 'jxsy',null,'id desc');
		    $this->assign('list', $list);
		}
		$this->display();
	}
    //实验课表管理
	public function sykbgl(){
		$this->display();
	}

}